package com.zwr.sheller.shop.controller;

import com.zwr.sheller.core.common.JsonResult;
import com.zwr.sheller.core.common.WQQBusinessException;
import com.zwr.sheller.core.pojo.Store;
import com.zwr.sheller.core.util.GetThreadLocal;
import com.zwr.sheller.core.util.ThreadLocalUtil;
import com.zwr.sheller.shop.service.StoreService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletRequest;
import java.util.Map;

/**
 * @Author: 18032
 * @Date: 16:12 2022/1/5
 */
@RestController
@RequestMapping("/store")
@CrossOrigin
@Api(tags = "店铺设置")
public class StoreController {
    @Autowired
    StoreService storeService;

    @PostMapping("/selectByStoreId")
    @ApiOperation("商铺设置:点击基本信息设置查询一次")
    public Map<String,Object> selectByStoreId() throws WQQBusinessException {
        Long storeId = GetThreadLocal.getStoreId();
        Store store = storeService.selectByStoreId(storeId);
        JsonResult jsonResult = new JsonResult();
        jsonResult.setField("data",store);
        jsonResult.setCode("200");
        return jsonResult.getMap();
    }

    @PostMapping("/updateStoreBasicMessage")
    @ApiOperation("商铺设置:点击保存,修改店铺基本信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "storeName",value = "店铺名称",dataType = "String",required = false),
            @ApiImplicitParam(name = "storeKeyName",value = "店铺关键字",dataType = "String",required = false),
            @ApiImplicitParam(name = "storePhone",value = "店铺客服电话",dataType = "String",required = false),
            @ApiImplicitParam(name = "storeAddress",value = "店铺网址",dataType = "String",required = false),
            @ApiImplicitParam(name = "storeLogo",value = "店铺logo地址",dataType = "String",required = false),
            @ApiImplicitParam(name = "storeTopic",value = "店铺公告",dataType = "String",required = false),
            @ApiImplicitParam(name = "storeDesc",value = "店铺描述",dataType = "String",required = false)
    })
    public Map<String,Object> updateStoreBasicMessage(Store store) throws WQQBusinessException {
        System.out.println("store:"+store);

        Integer integer = storeService.updateStoreBaseMessage(store);
        JsonResult jsonResult = new JsonResult();
        jsonResult.setCode("200");
        jsonResult.setMsg("修改成功");
        return jsonResult.getMap();
    }

    @PostMapping("/userGetStoreMessage")
    public Map<String,Object> userGetStoreMessage(Long storeId) throws WQQBusinessException {
        Map<String, Object> map = storeService.userGetStoreMessage(storeId);
        JsonResult jsonResult = new JsonResult();
        jsonResult.setCode("200");
        jsonResult.setField("data",map);
        return jsonResult.getMap();
    }



}
